# a. 生成一个存放1-100之间个位数为3的数据列表
lst= [n for n in range(1,101) if n % 10 == 3]
print(lst)
print("=" * 10)

# b. 利用列表推导式将已知列表中的整数提取出来
# 例如：[True, 17, "hello", "bye", 98, 34, 21] --- [17, 98, 34, 21]
lst = [True, 17, "hello", "bye", 98, 34, 21]
lst1 = []
for i,num in enumerate(lst):
    if type(num) == int:
        lst1.append(num)

print(lst1)
print("=" * 10)


# c.利用列表推导式存放指定列表中字符串的长度
# 例如 ["good", "nice", "see you", "bye"] --- [4, 4, 7, 3]
lst = ["good", "nice", "see you", "bye"]
lst2 = [len(n) for n in lst]
print(lst2)
print("=" * 10)


# d.生成一个列表，其中的元素为’0-1’，‘1-2’，‘2-3’，‘3-4’，‘4-5’
lst3 = [f'{n}-{n + 1}' for n in range(5)]
print(lst3)
print("=" * 10)

# 3.根据products列表写一个循环，不断询问用户想买什么，用户选择一个商品编号, 就把对应的商品添加到购物车里，最终用户输入q退出时，打印购买的商品列表。注意：本题可以自由发挥
# products = [["iphone",6888],["MacPro",14800],["小米6",2499],["Coffee",31],["Book",60],["Nike",699]]
# products = [["iphone",6888],["MacPro",14800],["小米6",2499],["Coffee",31],["Book",60],["Nike",699]]
products = [["1",6888],["2",14800],["3",2499],["Coffee",31],["Book",60],["Nike",699]]
for product,price in products:
    print(f'{product}\t{price}')

shopping_list = []
price = 0

while True:
    input_order = input("选择要购买的商品,输入q则退出购物")
    if input_order == "q":
        break

    for product, price in products:
        if input_order == product:
            shopping_list.append(product)
            price += price
            continue
        else:
            print(f'没有找到该商品')




if len(shopping_list) == 0:
    print("没有要购物的商品")
else:
    for product in shopping_list:
        print(product)
        print(f"合计:{price}")